<template>
	<view :data-theme='theme()' :class="theme() || ''">
		<template>
			<view class="user-index" style="font-size: 28rpx;">
				<!--个人信息-->
				<view class="user-header" style="padding-top: 160rpx;">
					<view class="user-header-inner" >
						<view class="user-info">
							<view class="photo">
								<image :src="detail.avatarUrl" mode="aspectFill"></image>
								<image style="position: absolute;right: 20rpx;top: 40rpx;" :src="UserState == 10?'/static/spz.png':UserState == 40?'/static/spjj.png':UserState == 30?'/static/jy.png':''" mode="aspectFill"></image>
							</view>
							<view class="info">
								<view class="d-c-c mb23">
									<view class="name">{{ detail.nickName }}</view>
									<text class="ml20 grade" v-if="detail.gradeId > 0">
										{{ userGrade }}
									</text>
								</view>
								<view class="tel d-s-c">
									<text class="f26">ID:{{ detail.userId }}</text>
								</view>
							</view>
						</view>
					</view>

					<!--账号余额-->
					<view class="my-order">
						<view class="list d-a-c flex-1">
							<view class="item d-c-c d-c" @click="jumpPage('/userpage/userinfo/wallet')">
								<view class=" red_mini">{{token && UserState == '20'? detail.balance:'**' }}</view>
								<text class="pt16 f24 gray3">账号余额</text>
							</view>
							<!-- <view class="item order_center d-c-c d-c" @click="jumpPage('/userpage/points/points')">
								<view class=" red_mini">{{ detail.points }}</view>
								<text class="pt16 f24 gray3">{{setting.pointsName}}</text>
							</view> -->
							<view class="item d-c-c d-c order_center_left" @click="jumpPage('/userpage/userinfo/walletDetail/voucher')">
								<view class="red_mini">{{ coupon }}</view>
								<text class="pt16 f24 gray3">优惠券</text>
							</view>
						</view>
					</view>
				</view>
				
				<!--我的资产-->
				<view class="my-assets">
					<view class="my-assets-all">
						<view class="f30 fb">我的订单</view>
						<view class="gray9 f26" @click="jumpPage('/orderpages/order/myorder?dataType=all')">
							查看全部<text class="icon iconfont icon-jiantou"></text></view>
					</view>
					<view class="d-b-c w100" style="display: flex;align-items: center;flex-wrap: wrap;gap:20rpx;justify-content: flex-start;">
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=payment')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-icon.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.payment != null && orderCount.payment > 0">{{ orderCount.payment }}</text>
							</view>
							<text>待付款</text>
						</view>
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=notConfirm')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-daifahuo.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.notConfirm != null && orderCount.notConfirm > 0">{{ orderCount.notConfirm }}</text>
							</view>
							<text class="">待确认</text>
						</view>
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=delivery')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-daifahuo.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.delivery != null && orderCount.delivery > 0">{{ orderCount.delivery }}</text>
							</view>
							<text class="">待发货</text>
						</view>
						
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=notPickup')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-daishouhuo.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.notPickup != null && orderCount.notPickup > 0">{{ orderCount.notPickup }}</text>
							</view>
							<text class="">待自提</text>
						</view>
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=notComment')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-quanbudingdan.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.notComment != null && orderCount.notComment > 0">{{ orderCount.notComment }}</text>
							</view>
							<text class="">待评价</text>
						</view>
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=commented')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-quanbudingdan.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.commented != null && orderCount.commented > 0">{{ orderCount.commented }}</text>
							</view>
							<text class="">已评价</text>
						</view>
						<view class="item" @click="jumpPage('/orderpages/order/myorder?dataType=refund')">
							<view class="icon-box pr">
								<image src="/static/icon/icon-tuikuan.png" mode=""></image>
								<text class="dot  d-c-c"
									v-if="orderCount.refund != null && orderCount.refund > 0">{{ orderCount.refund }}</text>
							</view>
							<text class="">退款</text>
						</view>
					</view>
				</view>

				<!--菜单-->
				<view class="menu-wrap">
						<view class="group-bd f-w" v-for="(item, index) in menus" :key="index"
							@click="jumpPage(item.path)">
							<view class="group-bd-name">
								<view>
									<image class="icon-round" :src="item.icon" mode="aspectFill"></image>
								</view>
								<text class="name">{{ item.name }}</text>
							</view>
							<view>
								<image class="mine_list_item_image" src="/static/my/right.png" mode=""></image>
							</view>
							
						</view>
						
				</view>
				<view v-if="invitation.isOpen && invitation.invitationId > 0">
					<view class="activity_img d-c-c" @click="toinvitation(invitation.invitationId)">
						<image :src="invitation.image" mode=""></image>
					</view>
				</view>

			</view>
		</template>
		<tabBar></tabBar>
	</view>
</template>

<script>
	import diy from '@/components/diy/diy.vue';
	export default {
		components: {
			diy
		},
		data() {
			return {
				items: [],
				/*签到数据*/
				sign: {},
				UserState:'10',
				/*是否加载完成*/
				loadding: true,
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				/*菜单*/
				menus: [
					{
						icon:'/static/my/xxxxxxx.png',
						path:'/userpage/userinfo/userinfo',
						name:'个人信息',
					},
					// {
					// 	icon:'/static/my/shezhivvvv.png',
					// 	path:'/userpage/address/address',
					// 	name:'地址管理',
					// },
					{
						icon:'/static/my/shezhidddddd.png',
						path:'/userpage/userinfo/invoice',
						name:'我的发票',
					},
					{
						icon:'/static/my/wallet.png',
						path:'/userpage/userinfo/wallet',  //上云丰
						// path:'/userpage/my-wallet/my-wallet', 
						name:'我的钱包',
					},
					{
						icon:'/static/my/kefu_icon.png',
						path:'',
						name:'联系客服',
					}
					
				],
				invitation: {},
				detail: {
					balance: 0,
					points: 0,
					grade: {
						name: ''
					},
				},
				orderCount: {},
				coupon: 0,
				setting: {},
				user_type: '', //用户状态
				sessionKey: '',
				userGrade: '',
				openDiy: true,
				wxBinding: false,
				SessionId:'',
				shopUserId:'',
				token:uni.getStorageSync('token'),
				UserState:uni.getStorageSync('UserState'),
			};
		},
		onShow() {
			this.getData();
			// 清楚我的订单页面选择的标签
			uni.setStorageSync('stateDataType', '');
		},
		onLoad(option) {
			let { scene } = option;
			scene = decodeURIComponent(scene);
			console.log(scene,'邀请绑定业务员')
			this.shopUserId = scene.split('=')[1];
			console.log(this.shopUserId,'邀请绑定业务员')
			if(this.shopUserId){
				uni.setStorageSync('shopUserId',this.shopUserId)
			}
			// 上云丰代码
			// this.SessionId = uni.getStorageSync('token');
			// if(!this.SessionId){
			// 	this.gotoPage('/pages/login/regitst')
			// }
			// let self = this;
			// self.wxBinding = uni.getStorageSync('wxBinding');
			// if (e.invitationId) {
			// 	uni.setStorageSync('invitationId', e.invitationId);
			// }
			// if (e.refereeId) {
			// 	uni.setStorageSync('refereeId', e.refereeId);
			// }
			// //#ifdef MP-WEIXIN
			// wx.login({
			// 	success(res) {
			// 		// 发送用户信息
			// 		self._post('user/userWx/getSession', {
			// 			code: res.code
			// 		}, result => {
			// 			self.sessionKey = result.data;
			// 		});
			// 	}
			// });
			// //#endif
		},
		methods: {
			// 获取审批状态
			getUserState(){
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._post('user/user/detail', {
					source: self.getPlatform()
				}, function(res) {
					// AUDIT("审批中", 10),
					// NORMAL("正常", 20),
					// DISABLE("禁用", 30),
					// REFUSE("审批拒绝",40),
					self.UserState = res.data.status
					uni.setStorageSync('UserState', self.UserState);
					console.log(self.status,'self.status')
					self.loadding = false;
					uni.hideLoading();
				});
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._post('user/index/index', {
					source: self.getPlatform()
				}, function(res) {
					console.log(res,'1234654')
					self.detail = res.data.user;
					self.coupon = res.data.coupon;
					self.orderCount = res.data.orderCount;
					// self.menus = res.data.menus;
					self.invitation = res.data.invitation;
					self.setting = res.data.setting;
					self.userGrade = res.data.userGrade;
					self.loadding = false;
					uni.hideLoading();
					this.getUserState();
				});
			},
			
			
			/*跳转页面*/
			jumpPage(path) {
				if(path == '/userpage/userinfo/wallet'){
					this.gotoPage(path+`?balance=${this.detail.balance}`); 
				}else if(path){
					this.gotoPage(path);
				}else{
					// 咨询客服
					//  uni.makePhoneCall({
					// 	phoneNumber: this.detail.mobile
					// });
					
					wx.openCustomerServiceChat({
						envVersion: 'release',
					extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcfed020b1e861f9ce'},
					corpId: 'ww85382703df74a845',
						success(res) {
						console.log('成功了',res)
						}
					})
				}
			},
			toinvitation(id) {
				if (id == 0) {
					uni.showToast({
						title: '暂无活动'
					})
				} else {
					this.gotoPage('/userpage/invite/invite?invitationGiftId=' + id);
				}
			},
			
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #EBEBEB;
	}
	.w100 {
		width: 100%;
	}

	.foot_ {
		height: 98rpx;
		width: 100%;
	}

	.user-header {
		position: relative;
		@include background_color('background_color');
	}

	.user-header .user-header-inner {
		position: relative;
		padding: 30rpx 30rpx 120rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		overflow: hidden;
		margin-bottom: 100rpx;
	}

	.user-header .user-header-inner::after,
	.user-header .user-header-inner::before {
		display: block;
		content: '';
		position: absolute;
		border-radius: 50%;
		z-index: 0;
	}

	.user-header .user-header-inner::after {
		width: 400rpx;
		height: 400rpx;
		right: -100rpx;
		bottom: -200rpx;
		background-image: radial-gradient(90deg, rgba(255, 255, 255, 0.2) 10%, rgba(255, 255, 255, 0));
	}

	.user-header .user-header-inner::before {
		width: 200rpx;
		height: 200rpx;
		left: -60rpx;
		top: -20rpx;
		background-image: radial-gradient(-90deg, rgba(255, 255, 255, 0.2) 10%, rgba(255, 255, 255, 0));
	}

	.user-header .user-info {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.user-header .photo,
	.user-header .photo image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.user-header .photo {
		border: 4rpx solid #ffffff;
	}

	.user-header .info {
		padding-left: 20rpx;
		box-sizing: border-box;
		overflow: hidden;
		color: #ffffff;
	}

	.user-header .info .name {
		font-weight: bold;
		font-size: 32rpx;
	}

	.user-header .info .tel {
		font-size: 28rpx;
	}

	.user-header .info .grade {
		display: block;
		padding: 0 16rpx;
		font-size: 22rpx;
		/* height: 36rpx; */
		line-height: 36rpx;
		border-radius: 40rpx;
		background-color: rgba($color: #000000, $alpha: 0.1);
		color: #ffffff;
	}

	.user-header .sign-box {
		position: absolute;
		right: 20rpx;
		padding: 0 10rpx;
		height: 50rpx;
		border: 1px solid #ffe300;
		border-radius: 25rpx;
		font-size: 24rpx;
		color: #ffe300;
		z-index: 10;
	}

	.user-header .sign-box .iconfont {
		color: #ffe300;
	}

	.user-header .my-order {
		position: absolute;
		padding: 0 30rpx;
		/* height: 240rpx; */
		right: 20rpx;
		bottom: -75rpx;
		left: 20rpx;
		box-sizing: border-box;
		border-radius: 16rpx;
		/* box-shadow: 0 0 6rpx 0 rgba(0, 0, 0, 0.1); */
		background: #ffffff;
		z-index: 10;
	}

	.order_center {
		border-left: 1rpx solid #D9D9D9;
		border-right: 1rpx solid #D9D9D9;
	}
	.order_center_left {
		border-left: 1rpx solid #D9D9D9;
	}

	.my-order .item {
		display: flex;
		margin: 20rpx 0;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;
		flex: 1;
	}

	.my-assets .icon-box image {
		width: 48rpx;
		height: 48rpx;
		margin-bottom: 16rpx;
	}

	.my-order .icon-box,
	.my-assets .icon-box {
		width: 60rpx;
		height: 60rpx;
	}

	.my-order .icon-box .iconfont,
	.my-assets .icon-box .iconfont {
		font-size: 50rpx;
		color: #333333;
	}

	.my-assets .icon-box .dot {
		position: absolute;
		top: -13rpx;
		right: -8rpx;
		height: 25rpx;
		min-width: 25rpx;
		padding: 4rpx;
		border-radius: 20rpx;
		font-size: 20rpx;
		background: linear-gradient(180deg, #FC4133, #FF7A04);
		color: #ffffff;
	}

	.my-assets {
		margin: 0 20rpx;
		padding: 30rpx;
		padding-top: 0;
		background: #ffffff;
		border-radius: 12rpx;
	}

	.my-assets .item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 115rpx;
	}

	.my-wallet {
		position: relative;
		width: 200rpx;
		border-left: 1px solid #dddddd;
	}

	.my-wallet::after {
		position: absolute;
		display: block;
		content: '';
		left: 0;
		border: 8rpx solid transparent;
		border-left-color: #dddddd;
	}

	.menu-wrap {
		margin: 0 20rpx;
		margin-top: 30rpx;
		background: #ffffff;
		/* box-shadow: 0 0 6rpx 0 rgba(0, 0, 0, 0.1); */
		border-radius: 12rpx;
	}

	.menu-wrap .group-bd {
		padding: 20rpx 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2rpx solid #ddd;
	}
	.menu-wrap .group-bd-name{
		display: flex;
		align-items: center;
		
	}
	.menu-wrap .mine_list_item_image{
		width: 15rpx;
		height: 15rpx;
		margin-right: 10rpx;
		margin-left: 5rpx;
	}
	.menu-wrap .item {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		width: 142rpx;
		height: 150rpx;
		font-size: 24rpx;
	}

	

	.menu-wrap .icon-round {
		width: 48rpx;
		height: 48rpx;
		color: #ffffff;
		margin-right: 10rpx;
	}

	.menu-wrap .item .iconfont {
		font-size: 40rpx;
		color: #ffffff;
	}

	.menu-wrap .item .name {
		margin-top: 19rpx;
	}

	.bind_phone {
		width: 100%;
		height: 80rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
	}

	.bind_content {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #ffffff;
		/* box-shadow: 0 0 6rpx 0 rgba(0, 0, 0, 0.1); */
		border-radius: 16rpx;
		height: 100%;
		padding: 0 20rpx;
	}

	.bind_txt {}

	.bind_btn {
		width: 134rpx;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 22rpx;
		border-radius: 25rpx;
		text-align: center;
		color: #FFFFFF;
		background-color: $dominant-color;
	}

	.vertical {
		position: absolute;
		top: 10px;
		right: 53px;
		z-index: 100000;
	}

	.vertical_img {
		width: 100rpx;
		height: 100rpx;
	}

	.f20 {
		margin-left: 5rpx;
		font-size: 19rpx;
	}

	.red_mini {
		color: #333333;
		font-size: 36rpx;
		font-weight: bold;
	}

	.icon-zhuanshutequan {
		color: #f5dca6;
		margin-right: 3px;
	}

	.news {
		position: absolute;
		top: 40rpx;
		right: 20rpx;
		z-index: 100;
	}

	.news .chat {
		width: 40rpx;
		height: 40rpx;
	}

	.news .icon-xiaoxi {
		font-size: 50rpx;
		color: #FFFFFF;
	}

	.news_num {
		position: absolute;
		top: 24rpx;
		right: 44rpx;
		z-index: 100;
		border-radius: 50%;
		width: 25rpx;
		height: 25rpx;
		text-align: center;
		line-height: 25rpx;
		color: #FFFFFF;
		background-color: #ff6633;
		padding: 5rpx;
		font-size: 20rpx;
	}

	.activity_img {}

	.activity_img image {
		width: 676rpx;
		height: 188rpx;
		margin: 0 auto;
		margin-top: 15rpx;
	}

	.my-assets-all {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 90rpx;
		line-height: 90rpx;
	}

	.my-assets-all .icon.icon-jiantou {
		font-size: 12px;
		color: #999999;
	}
</style>